import store from "../store/store.js"
import router from "../router/router.js"
import Vue from 'vue'

window._showControl = false;

window._ajax = {
  timeOut: 12000000,
  code: 1,
  error() {
    _methods.showLoading(false);
    mui.toast('服务器没有响应，请稍后重试！');
  },
  loading(val) {
    store.commit("_loadingShow", val);
  },
  login(data){
    if (data.code === -999) {
      _methods.goPath("/home");
      location.reload();
      mui.toast("登录超时");
    }
  },
  noLoading(url = "", data = {}, call = () => {
  }, type = "post") {
    let self = this;
    mui.ajax(_ajaxUrls.baseUrl + url, {
      data: data,
      dataType: 'json',
      type: type,
      timeout: this.timeOut,
      success(data) {
        self.login(data);
        if (data.code && data.code === window._ajax.code) {
          call(data);
        } else {
          mui.toast(data.msg);
        }
      },
      error() {
        self.error();
      }
    });
  },
  withLoading(url = "",
              data = {},
              call = () => {
              }, type = "post") {
    let self = this;
    self.loading(true);
    mui.ajax(_ajaxUrls.baseUrl + url, {
      data: data,
      dataType: 'json',
      type: type,
      timeout: this.timeOut,
      success(data) {
        self.login(data);
        self.loading(false);
        if (data.code === window._ajax.code) {
          call(data);
        } else {
          mui.toast(data.msg);
        }
      },
      error() {
        self.loading(false);
        self.error();
      }
    });
  },
  withLoadingDelete(url = "", data = {}, call = () => {
  }) {
    let self = this;
    self.loading(true);
    mui.ajax(_ajaxUrls.baseUrl + url, {
      data: data,
      dataType: 'json',
      type: "delete",
      contentType: "application/json",
      timeout: this.timeOut,
      success(data) {
        self.login(data);
        self.loading(false);
        if (data.code === 200) {
          call(data);
        } else {
          mui.toast(data.msg);
        }
      },
      error() {
        self.loading(false);
        self.error();
      }
    });
  },
  confirmWithLoading(url, data, call, type, txt) {
    _alert.confirm(() => {
        this.withLoading(url, data, call, type);
      },
      txt,
      undefined, () => {
        this.loading(false);
      });
  },
};

window._alert = {
  alert(call, txt = "处理成功") {
    mui.alert(txt, '', () => {
      call && call();
    });
  },
  alertGOBack(txt) {
    this._alert(() => {
      _methods.scrollTriggerDownScroll();
      _methods.goBack();
    }, txt)
  },
  confirm(call, txt = "是否确认处理？", btn = ['取消', '确认'], cancel = () => {
  }) {
    mui.confirm(txt, '', btn, (e) => {
      if (e.index == 1) {
        call();
      } else {
        cancel();
      }
    });
  },
  promt(call, txt = "是否确认处理？", btn = ['取消', '确认'], cancel = () => {
  }, ph = "") {
    mui.prompt(txt, ph, "", btn, (e) => {
      if (e.index == 1) {
        call(e);
      } else {
        cancel();
      }
    });
  },
};

window._data = {
  userInfo: {
    name: "",
    userId: 0,
    deptId: 0,
    deptName: "",
    phoneNumber: "",
    roleRank: "",
    ready: false,
  },
  logoUrl: "/Ecs/systemSetting/imLogo",
  pageSize: 20,
  test: false,
  bus: new Vue(),
  busInit: {
    on_(call, flag = store.state.headerRightType.val) {
      _data.bus.$on(_data.headerClick.emitLabel + flag, () => {
        call();
      });
    },
    off_(flag = store.state.headerRightType.val) {
      _data.bus.$off(_data.headerClick.emitLabel + flag);
    }
  },
  headerClick: {
    emitLabel: "headerRightClick",
    _off(flag) {
      this.ret();
      _data.bus.$off(this.emitLabel + flag);
    },
    ret() {
      store.commit("_headerRightType", {
        val: 99,
        txt: ""
      });
    }
  },
  actionDataTalk: [
    {txt: '发起对话', iconClass: "action-icon-chat", value: 2},
    {txt: '拨打电话', iconClass: "action-icon-call", value: 1}
  ],
  actionItemChecked: null,
  eventLevel: ['', '特别重大', '重大', '较大', '一般', '其他'],
  riskLevel: ["", "红色", "橙色", "黄色", "蓝色", "风险提示"],
  riskLevel2: ["", "很高", "高", "中等", "低", "很低"],
  infoList: [],
  peopleList: [],
  leaderList: [],
  orgList: [],
  csList: [],
  teamList: [],
  eventFeedBackType: [],
  submitType: [],
  selectHolder: "请选择 >",
  processSubmitData: {
    needSiteDisposal: 0,
    operateType: 99,
    userIds: "",
  },
};

window._methods = {
  setSeesion(key, val) {
    sessionStorage.setItem(key, val);
  },
  getSession(key) {
    return sessionStorage.getItem(key);
  },
  copyObj(p, c = {}) {
    for (let i in p) {
      if (typeof p[i] === 'object') {
        c[i] = (p[i].constructor === Array) ? [] : {};
        this.copyObj(p[i], c[i]);
      } else {
        c[i] = p[i];
      }
    }
    return c;
  },
  setValue(id, val) {
    let ele = document.getElementById(id);
    if (ele) {
      ele.value = val;
    }
  },
  getValue(id) {
    let ele = document.getElementById(id);
    if (ele) {
      return ele.value;
    } else {
      return false;
    }
  },
  arrToString(arr, key) {
    if (arr.length) {
      return arr.map((i) => {
        return i[key]
      }).join(",");
    } else {
      return ""
    }
  },
  CheckImgExists(imgurl) {
    var ImgObj = new Image(); //判断图片是否存在
    ImgObj.src = imgurl;
    //没有图片，则返回-1
    if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
      console.log(1);
      return true;
    } else {
      console.log(2);
      return false;
    }
  },
  checkRequired(data, type = 0) {
    let flag = true;
    if (data.length) {
      data.forEach((i) => {
        i.list.forEach((i) => {
          if (type == 2) {
            if (i.attributesValue == _data.selectHolder || !i.attributesValue) {
              i.attributesValue = "";
            }
          }
          else {
            if (i.isRequired == 1 && flag && !i.attributesValue && i.attributesValue != _data.selectHolder) {
              flag = false;
              mui.toast("请填写" + i.label);
              return false;
            }
          }
        });
      });
    }
    return flag;
  },
  backToTop(id, rate, offSet = 0, className = "") {
    let doc = className ? document.querySelectorAll(className)[0] : document.getElementById(id);
    let scrollTop = doc.scrollTop;
    let top = function () {
      scrollTop = scrollTop + (0 - scrollTop) / (rate || 2);
      if (scrollTop < 1) {
        doc.scrollTop = offSet;
        return;
      }
      let os = offSet != 0 ? offSet : scrollTop;
      doc.scrollTop = scrollTop;
      requestAnimationFrame(top);
    };
    top();
  },
  isPhone(){
    return new Promise(resolve => {
      let h = location.hash.split("?"),
        n = h[0].split("#")[1],//路由地址
        p = h[1] ? ('?' + h[1]) : '';//参数内容
      n = n || '';
      let sUserAgent = navigator.userAgent.toLowerCase();
      let bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
      let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
      let bIsMidp = sUserAgent.match(/midp/i) == "midp";
      let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
      let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
      let bIsAndroid = sUserAgent.match(/android/i) == "android";
      let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
      let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
      if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {
        let title = _methods.getUrlParam("title").toString();
        let id = _methods.getUrlParam("id");
        let pl = "";
        switch (title) {
          case "40":
            pl = `/Ecs/pc/index.html#/todayDesc?id=${id}`;
            break;
          case "50":
            pl = `/Ecs/pc/index.html#/todayDesc?id=${id}`;
            break;
          case "7":
            pl = `/Ecs/pc/index.html#/reportDesc?id=${id}`;
            break;
          case "20":
            pl = `/Ecs/pc/index.html#/eventRiskDesc?&type=2&id=${id}`;
            break;
          case "30":
            pl = `/Ecs/pc/index.html#/eventRiskDesc?&type=3&id=${id}`;
            break;
          case "120":
            pl = `/Ecs/pc/index.html#/taskDesc?type=3&id=${id}`;
            break;
          case "130":
            pl = `/Ecs/pc/index.html#/taskDesc?type=2&id=${id}`;
            break;
          case "90":
            pl = `/Ecs/pc/index.html#/taskDesc?id=${id}&read=1`;
            break;
          default:
            pl = "/Ecs/pc/index.html#/";//PC端
            break;
        }
        // alert(pl);
        window.location.href = pl;
      }
      else {
        resolve(true);
      }
    });
  },
  //自定义下拉刷新
  initMeScroll(mescrollId, options) {
    //下拉刷新的布局内容
    let htmlContent = '<div class="downwarp-unload"><p class="downwarp-arrow"></p><p class="downwarp-tip">下拉刷新</p></div>';
    htmlContent += '<div class="downwarp-onload"><p class="downwarp-progress"></p><p class="downwarp-tip">加载中</p></div>';
    //自定义的配置
    let myOption = {
      down: {
        auto: false,
        offset: 60, //触发刷新的距离
        htmlContent: htmlContent, //布局内容
        inited: function (mescroll, downwarp) {
          //初始化完毕的回调,可缓存dom
          mescroll.downOnLoadDom = downwarp.getElementsByClassName("downwarp-onload")[0];
          mescroll.downUnloadDom = downwarp.getElementsByClassName("downwarp-unload")[0];
          mescroll.downTipDom = downwarp.getElementsByClassName("downwarp-tip")[0];
          mescroll.downArrowDom = downwarp.getElementsByClassName("downwarp-arrow")[0];
        },
        inOffset: function (mescroll) {
          //进入指定距离范围内那一刻的回调
          mescroll.downOnLoadDom.style.display = "none";
          mescroll.downUnloadDom.style.display = "block";
          mescroll.downTipDom.innerText = "下拉刷新";
          mescroll.downArrowDom.style.webkitTransform = "rotate(0deg)";
          mescroll.downArrowDom.style.transform = "rotate(0deg)";
        },
        outOffset: function (mescroll) {
          //下拉超过指定距离那一刻的回调
          mescroll.downTipDom.innerText = "释放更新";
          mescroll.downArrowDom.style.webkitTransform = "rotate(-180deg)";
          mescroll.downArrowDom.style.transform = "rotate(-180deg)";
        },
//			onMoving: function(mescroll, rate, downHight) {
//				//下拉过程中的回调,滑动过程一直在执行; rate下拉区域当前高度与指定距离的比值(inOffset: rate<1; outOffset: rate>=1); downHight当前下拉区域的高度
//			},
        showLoading: function (mescroll) {
          //触发下拉刷新的回调
          mescroll.downOnLoadDom.style.display = "block";
          mescroll.downUnloadDom.style.display = "none";
          mescroll.downTipDom.innerText = "下拉刷新";
          mescroll.downArrowDom.style.webkitTransform = "rotate(0deg)";
          mescroll.downArrowDom.style.transform = "rotate(0deg)";
        }
      },
      up: {
        auto: true,
        loadFull: {
          use: false,
          delay: 500
        },
        page: {
          size: _data.pageSize
        },
        noMoreSize: 7,
        empty: {
          tip: `-- 暂无更多数据 --`, //首次加载 无数据提示
        },
        hardwareClass: "mescroll-hardware",
        // htmlNodata: `<p class="upwarp-nodata">-- 暂无更多数据 --</p>`,
        htmlNodata: ``,
        // showNoMore(mescroll,upwarp){
        //   console.log(mescroll);
        //   console.log(upwarp);
        // },
        // toTop: {
        //     src: "option/mescroll-totop.png" //回到顶部按钮的图片路径
        // }
      }
    };
    //加入自定义的默认配置
    options = MeScroll.extend(options, myOption);
    //创建MeScroll对象
    return new MeScroll(mescrollId, options);
  },
  //主动下拉刷新
  meScrollTriggerDownScroll(el) {
    el.triggerDownScroll();
  },
  //主动下拉刷新数组
  meScrollTriggerDownScrollArr(arr) {
    arr.forEach((i) => {
      i.triggerDownScroll();
    });
  },
  //防抖
  deBounce(something, delay) {
    if (window.debounceF) clearTimeout(window.debounceF);
    window.debounceF = setTimeout(function () {
      something();
    }, delay);
  },
  togClass(el, className) {
    if (el.classList) {
      el.classList.toggle(className);
    } else {
      let classes = el.className.split(' ');
      let existingIndex = classes.indexOf(className);

      if (existingIndex >= 0)
        classes.splice(existingIndex, 1);
      else
        classes.push(className);

      el.className = classes.join(' ');
    }
  },
  showLoading(val) {
    store.commit("_loadingShow", val);
  },
  formatDate(date, fmt) {
    date = date == undefined ? new Date() : date;
    date = typeof date == 'number' ? new Date(date) : date;
    fmt = fmt || 'yyyy-MM-dd HH:mm:ss';
    let obj =
      {
        'y': date.getFullYear(), // 年份，
        'M': date.getMonth() + 1, // 月份，
        'd': date.getDate(), // 日期
        'q': Math.floor((date.getMonth() + 3) / 3), // 季度
        'w': date.getDay(), // 星期，
        'H': date.getHours(), // 24小时制
        'h': date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, // 12小时制
        'm': date.getMinutes(), // 分钟
        's': date.getSeconds(), // 秒
        'S': date.getMilliseconds() // 毫秒
      };
    let week = ['日', '一', '二', '三', '四', '五', '六'];
    for (let i in obj) {
      fmt = fmt.replace(new RegExp(i + '+', 'g'), function (m) {
        let val = obj[i] + '';
        if (i == 'w') return (m.length > 2 ? '星期' : '周') + week[val];
        for (let j = 0, len = val.length; j < m.length - len; j++) val = '0' + val;
        return m.length == 1 ? val : val.substring(val.length - m.length);
      });
    }
    return fmt;
  },
  getUrlParam(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    let params = "";
    let val = "";
    if (window.location.search) {
      params = window.location.search.substr(1).match(reg);
    } else if (window.location.hash && window.location.hash.split("?")[1]) {
      params = window.location.hash.split("?")[1].match(reg);
    }
    if (params != null) {
      val = decodeURI(params[2]);
    }
    return val;
  },
  goBack(index = -1) {
    this.isPushCloseWindow().then(() => {
      store.dispatch("headerAnimate_action", 1);
      window.history.go(index);
    });
  },
  headerTitleChange(v, flag = false) {
    if (!flag) {
      store.dispatch("headerAnimate_action", 0);
    }
    store.dispatch("showFlag_action", v);
  },
  goPath(path, flag) {
    flag && headerTitleChange(flag);
    router.push({path: cookiePath + path});
  },
  goPeopleList(index, code) {
    let path = {
      3: "/detail",
      4: "/todayBulletin",
    }[index];
    this.goPath(`${path}/people?code=${code}`);
  },
  //主动下拉刷新列表
  scrollTriggerDownScroll() {
    window.pendingScroll.triggerDownScroll();
    window.completeScroll.triggerDownScroll();
  },
  actionChat(i, val = _data.actionItemChecked) {
    let phone = val.userInfo.cellphone;
    if (i === 1) {
      vrv.jssdk.callPhone({
        phoneNum: phone,
        success: function success(res) {
        }
      });
    } else {
      vrv.jssdk.openChat({
        chatId: val.userInfo.linkdoodID,
        success: function success(res) {

        }
      });
    }
  },
  headerRightShow(val = {val: 99, txt: ""}) {
    store.commit("_headerRightType", val);
  },
  sVal(id, txt, val = txt) {
    let el = document.getElementById(id);
    if (el) {
      el.value = txt;
      el.setAttribute("data-value", val);
    }
  },
  setAttribute(id, name = "data-value", val) {
    document.getElementById(id).setAttribute(name, val);
  },
  getAttribute(id, name = "data-value") {
    return document.getElementById(id).getAttribute(name);
  },
  isTodo(id){
    return id == _data.userInfo.userId;
  },
  fileDownLoad(item) {
    let url = `/Ecs/sys/attachment/download?fileUrl=${item.url}&fileName=${item.name}`;
    let eleLink = document.createElement('a');
    eleLink.download = item.name;
    eleLink.href = url;
    document.body.appendChild(eleLink);
    eleLink.click();
    eleLink.remove();
  },
};

//1领导(20904511138)//2值班员(20904511194)
// 3地方网信办(20904511204 20904511148) 4运营单位(20904511153 20904511160)
// 5安全厂商(20904511152 20904511196) 6专家(20904511200)

_data.userInfo.userId = 20904511204;
if (process.env.NODE_ENV == 'development') {
  _data.test = true;
  _methods.showLoading(false);
}
else {
  _data.test = false;
}

_methods.isNotPush = () => {
  return new Promise((resolve, reject) => {
    if (window.location.href.indexOf("isPush") == -1) {
      _methods.userInfoGet().then(() => {
        resolve(0);
      });
    } else {
      reject(1);
    }
  });
};

_methods.userInfoGet = () => {
  return new Promise(resolve => {
    if (_data.userInfo.ready) {
      resolve(true);
    }
    else {
      _ajax.noLoading(window._ajaxUrls.userIdGet.url + '/' + _data.userInfo.userId,
        {},
        (ajData) => {
          let val = ajData.result;
          _data.userInfo.deptId = val.orgID;
          _data.userInfo.name = val.linkdoodName;
          _data.userInfo.deptName = val.orgName;
          _data.userInfo.phoneNumber = val.cellphone;
          _data.userInfo.roleRank = val.role.roleRank;
          _data.userInfo.ready = true;
          if (window._homeData.showControl.first.indexOf(window._data.userInfo.roleRank) != -1) {
            _data.userInfo.isCenter = true;
          }
          if (window._homeData.showControl.sec.indexOf(window._data.userInfo.roleRank) != -1) {
            _data.userInfo.isCenter = false;
          }
          store.commit("_userInfo", _data.userInfo);
          resolve(true);
        },
        window._ajaxUrls.userIdGet.type);
    }
  })
};

_data.userInfo.isCenterInit = (call1, call2) => {
  if (_data.userInfo.isCenter) {
    call1();
  } else {
    call2();
  }
};

window._filterData = {
  isHttp(str) {
    let http = /^(https?|ftp|file):\/\//;
    if (!http.test(str)) {
      str = 'http://' + str
    }
    return str;
  },
  isIp(ip) {
    let reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;

    let flag = reg.test(ip);

    if (!flag) {
      mui.toast("请正确填写IP，ip示例:192.168.1.1")
    }

    return flag;
  },
  isYm(ym) {

    let reg = /[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/;

    let flag = reg.test(ym);

    if (!flag) {
      mui.toast("请正确填写域名，域名示例:a.gov.com")
    }

    return flag;
  },
  isUrl(url, ta = false) {

    let reg = /^(https?|ftp|files):\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;

    let flag = reg.test(url);

    if (!flag && !ta) {
      mui.toast("请正确填写url，url示例:http://www.baidu.com/");
    }

    return flag;
  },
  isFax(fax) {
    return /^(\d{3,4}-)?\d{7,8}$/.test(fax)
  },
};

_methods.authorGet = {
  init() {
    _methods.deBounce(() => {
      mui.ajax({
        type: 'GET',
        url: `${_ajaxUrls.baseUrl}tourist/redirectOAuth`,
        dataType: 'json',
        success: function (r) {
          if (r.code === 0) {
            window.location.href = r.data;
          } else {
            mui.toast(r.msg);
          }
        },
        error: function () {
          mui.toast('Error From OAuth！');
        }
      });
    }, 200);
  },
  isFail(data) {
    if (data.code && data.code === -999) {
      this.init();
    }
  }
};

window._vrvInit = {
  isPush() {
    return _methods.isNotPush().then(() => {
      return new Promise(resolve => {
        resolve(true);
      });
    }, () => {
      return this.init();
    });
  },
  init() {
    let userInfoReady;
    if (_data.test) {
      userInfoReady = _methods.userInfoGet();
    } else {
      if (_data.userInfo.ready) {
        userInfoReady = new Promise(userReady => {
          userReady(true);
        });
      } else {
        userInfoReady = new Promise(userReady => {
          return _methods.isPhone()
            .then(() => {
              return new Promise(resolve => {
                vrv.ready(function () {
                  resolve(true);
                })
              });
            })
            .then(() => {
              return new Promise(resolve => {
                vrv.jssdk.showNavigationBar({show: false});
                vrv.jssdk.getAccountInfo({
                  success: function success(res) {
                    _data.userInfo.userId = res.mUserId;
                    resolve(true);
                  }
                });
              });
            })
            //进入页面
            .then(() => {
              _methods.userInfoGet().then(() => {
                _methods.showLoading(false);
                userReady(true)
              });
            });
        });
      }
    }
    return userInfoReady;
  },
  voiceToTxt(call, type) {
    vrv.jssdk.speech2Text({
      type: type, // 1、开始 2、 停止 3 、 取消   默认 1
      success: function (i) {
        call(i.resultContent);
      }
    })
  },
  closeWindow() {
    vrv.jssdk.closeView({});
  },
  isPushCloseWindow() {
    _methods.isNotPush().then(() => {

    }, () => {
      _vrvInit.closeWindow();
    });
  },
  uploadFile(size = 10) {
    _ajax.loading(true);
    return new Promise(resolve => {
      vrv.jssdk.getLocalFiles({
        size: size,
        success: function (res) {
          _ajax.loading(false);
          let files = res.mFilePath.map((path, index) => {
            return {name: res.mFileName[index], url: path};
          });
          resolve(files);
        }
      })
    });
  },
  openFile(url) {
    vrv.jssdk.openFileURL({
      url: url,// 图片或文件url
      success(data) {
      }
    })
  }
};

_methods.temFormat = (data) => {
  return data.map(i => {
    if (i.element == 'text') {
      i.singLine = 1;
    }
    if (i.element == 'number') {
      i.singLine = 1;
    }
    if (i.element == 'checkbox') {
      i.options = JSON.parse(i.options);
      i.attributesValue = [];
      i.optionChecked = [];
    }
    if (i.element == 'radio' || i.element == 'select') {
      i.singLine = 1;
      i.options = JSON.parse(i.options);
      i.layer = 1;
      i.options = i.options.map(i => {
        return {text: i.key, value: i.value};
      });
    }
    if (i.element == 'datetime') {
      i.singLine = 1;
    }
    if (i.element == 'file') {
      if (i.isReadonly && i.attributesValue) {
        i.attributesValue = JSON.parse(i.attributesValue);
      } else {
        i.attributesValue = [];
      }
    }
    i.attributesID = i.id;
    return i;
  });
};

_methods.temRead = (data) => {
  return data.map(i => {
    i.isRequired = false;
    i.isReadonly = true;
    if (i.element == 'file') {
      if (i.attributesValue) {
        i.attributesValue = JSON.parse(i.attributesValue);
      } else {
        i.attributesValue = [];
      }
    }
    else {
      i.element = "read";
    }
    return i;
  });
};

_methods.tem = (data) => {
  return data.map(i => {
    i.isRequired = false;
    i.isReadonly = true;
    if (i.element == 'file') {
      if (i.attributesValue) {
        i.attributesValue = JSON.parse(i.attributesValue);
      } else {
        i.attributesValue = [];
      }
    }
    else {
      i.element = "read";
    }
    return i;
  });
};

_methods.temSubmit = (data) => {
  return data.filter(i => {
    if (i.element == 'checkbox') {
      i.attributesValue = _methods.arrToString(i.optionChecked, "key");
    }
    if (i.element == 'file') {
      if (i.attributesValue.length) {
        i.attributesValue = JSON.stringify(i.attributesValue);
      } else {
        i.attributesValue = "";
      }
    }
    return i.isSubmit != 99;
  });
};

//读取草稿箱
_methods.temLoad = (data) => {
  return data.map(i => {
    if (i.element == 'checkbox') {
      i.options = JSON.parse(i.options);
      let checked = [];
      if (i.attributesValue) {
        let c = i.attributesValue.split(",");
        i.options.forEach(i => {
          c.forEach(ii => {
            if (i.key == ii) {
              checked.push(i);
            }
          });
        });
      }
      i.optionChecked = checked;
    }
    if (i.element == 'file') {
      if (i.attributesValue) {
        i.attributesValue = JSON.parse(i.attributesValue);
      } else {
        i.attributesValue = [];
      }
    }
    if (i.element == 'datetime') {
      i.singLine = 1;
    }
    if (i.element == 'text') {
      i.singLine = 1;
    }
    if (i.element == 'number') {
      i.singLine = 1;
    }
    if (i.element == 'radio' || i.element == 'select') {
      i.singLine = 1;
      i.options = JSON.parse(i.options);
      i.layer = 1;
      i.options = i.options.map(i => {
        return {text: i.key, value: i.value};
      });
    }
    i.attributesID = i.id;
    return i;
  });
};







